﻿using System;
using System.Collections.Generic;

namespace CopyRightCodeCollector.Collectors {

    public class LineCollector : IDisposable {

        readonly string outputPath;
        readonly Queue<string> queue;
        readonly Action<string, IEnumerable<string>> outputer;

        public int Count => queue.Count;

        public LineCollector(string outputPath, Action<string, IEnumerable<string>> outputer) {
            this.outputPath = outputPath;
            this.queue = new Queue<string>();
            this.outputer = outputer;
        }

        public virtual void Shift() {
            this.queue.Dequeue();
        }

        public virtual void Add(string line) {
            this.queue.Enqueue(line);
        }

        protected virtual void Output() {
            this.outputer?.Invoke(this.outputPath, this.queue);
        }

        public void Dispose() {
            this.Output();
            GC.SuppressFinalize(this);
        }
    }
}
